home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_01_04
/
1n04068a
< prev
next >
Wrap
Text File
|
1990-08-05
|
3KB
|
140 lines
/* wrld8.cpp */
#include <stdio.h>
#include <stdlib.h>
#include <typedefs.hpp>
extern "C"
{
#include <tiga.h>
#include <extend.h>
}
#define gspPoints( n, p, q ) \
dm_ptrx( USER_DM( gspWorld | 0 ), n * sizeof(POINT), \
p, n * sizeof(POINT), q )
#define gspDraw( ) cp_cmd( USER_CP( gspWorld | 1 ), 0 )
struct POINT
{
int x;
int y;
};
int gspWorld;
POINT snd_points[5] =
{
25, 25, 75, 25, 50, 50, 25, 75, 75, 75
};
POINT rcv_points[5];
void reportPositionTable( )
{
printf( "Text displayed at:\n" );
for( int i = 0; i < 5; i++ )
printf( " %4d, %4d ==> %4d %4d \n", snd_points[i].x,
snd_points[i].y, rcv_points[i].x, rcv_points[i].y );
}
int main( int argc, char argv[ ] )
{
if( set_videomode( TIGA, INIT | CLR_SCREEN ) )
{
if( install_primitives( ) >= 0 )
{
gspWorld = install_rlm( "gspWrld8.rlm" );
if( gspWorld < 0 )
{
printf("ERROR: could not load gspWrld8.rlm\n");
printf("Error code = %d\n", gspWorld );
exit( 7 );
}
gspPoints( 5, snd_points, rcv_points );
gspDraw( );
reportPositionTable( );
}
else
{
printf( "ERROR: Can not load TIGA primitives.\n" );
return 1;
}
set_videomode( PREVIOUS, NO_INIT );
}
else
{
printf( "ERROR: Please install TIGA and try again.\n" );
return 2;
}
return 0;
}
/* gspWrld8.c */
#include <gsptypes.h>
#include <gspglobs.h>
#include <gsptiga.h>
#define XSIZE (config.mode.disp_hres)
#define YSIZE (config.mode.disp_vres)
#define XOR 10
#define MAX_POINTS 10
static int pointCount;
static int xPosition[MAX_POINTS];
static int yPosition[MAX_POINTS];
void gspPoints( p )
short* p;
{
int count;
int x, y, i;
count = *p++; /* get count (in bytes). */
count = count /4; /* number of points */
if( count > MAX_POINTS ) /* protect against array
overflow */
count = MAX_POINTS;
for( i = 0; i < count; i++ )
{
*p++ = xPosition[i] = *p * XSIZE / 100;
*p++ = yPosition[i] = *p * YSIZE / 100;
}
pointCount = count;
}
void gspDraw( )
{
int count;
int i;
int tw;
char* hello;
count = pointCount; /* number of points */
set_fcolor( WHITE );
set_bcolor( BLACK );
hello = " H e l l o W o r l d ";
tw = text_width( hello ); /* string width for
centering */
for( i = 0; i < count; i++ )
{
text_out( xPosition[i] - tw/2, yPosition[i],
" H e l l o W o r l d " );
}
}